package assql
{
	import assql.events.SQLErrorEvent;
	
	public class SQLResponder
	{
		private var resultHandler:Function;
		private var responseHandler:Function;
		private var parametersHandler:Function;
		private var errorHandler:Function;
		
		public function SQLResponder(errorHandler:Function=null, resultHandler:Function=null, responseHandler:Function=null, parametersHandler:Function=null)
		{
			this.errorHandler = errorHandler;
			this.resultHandler = resultHandler;
			this.responseHandler = responseHandler;
			this.parametersHandler = parametersHandler;
		}
		
		assql_internal function callResultHandler(result:ResultSet, token:SQLToken):void {
			if ( resultHandler != null ) {
				resultHandler(result, token);
			}
		}
		
		assql_internal function callResponseHandler(response:SQLResponse, token:SQLToken):void {
			if ( responseHandler != null ) {
				responseHandler(response, token);
			}
		}
		
		assql_internal function callParametersHandler(params:SQLParameters, token:SQLToken):void {
			if ( parametersHandler != null ) {
				parametersHandler(params, token);
			}
		}
		
		assql_internal function callErrorHandler(error:SQLErrorEvent, token:SQLToken):void {
			if ( errorHandler != null ) {
				errorHandler(error, token);
			}
		}
	}
}